package com.higgins.lawapp.server;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.higgins.lawapp.client.settings.dataItemModel.DataItemDTO;
import com.higgins.lawapp.client.settings.dataItemModel.DataItemInstanceDTO;
import com.higgins.lawapp.client.settings.dataItemModel.DataItemLevelDTO;
import com.higgins.lawapp.client.settings.dataItemModel.DataItemSourceDTO;
import com.higgins.lawapp.client.settings.dataModel.DataSourceDTO;
import com.higgins.lawapp.client.settings.dataModel.DataSourceLevelDTO;
import com.higgins.lawapp.client.settings.dataModel.DataSourceObjectDTO;
import com.higgins.lawapp.server.dataItemModel.DataItem;
import com.higgins.lawapp.server.dataItemModel.DataItemContainer;
import com.higgins.lawapp.server.dataItemModel.DataItemInstance;
import com.higgins.lawapp.server.dataItemModel.DataItemLevel;
import com.higgins.lawapp.server.dataItemModel.DataItemSource;
import com.higgins.lawapp.server.dataModel.DataSource;

public class DataCollectionServlet extends HttpServlet	{
	private static final long serialVersionUID = 1L;
	private DataCollectionEngine dataCollectionEngine = new DataCollectionEngine();
	private DataCollectionStoreEngine dataCollectionStoreEngine = new DataCollectionStoreEngine();

	public void doGet(HttpServletRequest req, HttpServletResponse resp)	throws IOException	{
		System.out.println("Start Collection!");
		dataCollectionEngine.clearVariablesForNewRun();
		dataCollectionStoreEngine.openConnection();
		List<DataSource> dataSources = dataCollectionStoreEngine.retrieveDataSources();
		startTheDataCollection(dataSources);
		dataCollectionStoreEngine.closeConnection();
		System.out.println("End Collection!");
	}	
	
	
	
	
	
	
	
	public void startTheDataCollection(List<DataSource> dataSources)	{
		try	{
			for (DataSource dataSource:dataSources)	{
				dataCollectionEngine.collectDataSource(dataSource);
			}
		} catch (Exception e)	{
			String exception = e.toString();
		}
	}
}
